home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / misc / wgrab.lha / RCS.RCSfiles / wshot.c,v < prev   
Text File  |  1995-10-29  |  10KB  |  286 lines

  1. head    1.2;
  2. access;
  3. symbols;
  4. locks
  5.     aris:1.2; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.2
  10. date    95.10.29.09.41.56;    author aris;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    95.10.29.09.26.14;    author aris;    state Exp;
  16. branches;
  17. next    1.0;
  18.  
  19. 1.0
  20. date    95.10.13.09.25.58;    author aris;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Grab Functions for WGrab DataTypes
  27. @
  28.  
  29.  
  30. 1.2
  31. log
  32. @Killed Typeo Errors (Dummy Revision)
  33. @
  34. text
  35. @/* $Id: wshot.c,v 1.1 1995/10/29 09:26:14 aris Exp aris $
  36. */
  37. #include <intuition/IntuitionBase.h>
  38. #include <graphics/gfxbase.h>
  39. #include <datatypes/pictureclass.h>
  40. #include <exec/memory.h>
  41. #include <dos/dos.h>
  42.  
  43. #include <clib/datatypes_protos.h>
  44. #include <clib/intuition_protos.h>
  45. #include <clib/graphics_protos.h>
  46. #include <clib/alib_protos.h>
  47. #include <clib/exec_protos.h>
  48. #include <clib/dos_protos.h>
  49. #include <clib/macros.h>
  50.  
  51. extern struct IntuitionBase *IntuitionBase;
  52. extern struct Library *DataTypesBase;
  53.  
  54. VOID
  55. SavePicture(Object *Picture,const STRPTR FileName)
  56. {
  57.         BPTR FileHandle;
  58.  
  59.         if(FileHandle = Open(FileName,MODE_NEWFILE))
  60.         {
  61.                 if(DoMethod(Picture,DTM_WRITE,NULL,FileHandle,DTWM_IFF,NULL))
  62.                         Close(FileHandle);
  63.                 else
  64.                 {
  65.                         Close(FileHandle);
  66.  
  67.                         DeleteFile(FileName);
  68.                 }
  69.         }
  70.  
  71.         DisposeDTObject(Picture);
  72. }
  73.  
  74. Object *
  75. GetPicture(BOOL scr)
  76. {
  77.         struct RastPort *RPort;
  78.  
  79.         if(RPort = (struct RastPort *)AllocVec(sizeof(struct RastPort),MEMF_ANY))
  80.         {
  81.                 struct BitMap   *BitMap;
  82.                 ULONG                    IntuiLock;
  83.                 struct Window   *Window;
  84.                 LONG                     Left,Top,
  85.                                          Width,Height,
  86.                                          PageWidth,PageHeight,
  87.                                          Depth;
  88.                 BOOL                     Locked = TRUE;
  89.                 struct Screen *Screen;
  90.  
  91.                 InitRastPort(RPort);
  92.  
  93.                 IntuiLock = LockIBase(NULL);
  94.  
  95.                 if(!scr) {
  96.  
  97.                     Window          = IntuitionBase -> ActiveWindow;
  98.  
  99.                     Left            = Window -> LeftEdge;
  100.                     Top             = Window -> TopEdge;
  101.                     Width           = Window -> Width;
  102.                     Height          = Window -> Height;
  103.                     PageWidth       = Window -> WScreen -> Width;
  104.                     PageHeight      = Window -> WScreen -> Height;
  105.                     Depth           = GetBitMapAttr(Window -> RPort -> BitMap,BMA_DEPTH);
  106.                     }
  107.                 else {
  108.  
  109.                     Screen          = IntuitionBase -> ActiveScreen;
  110.  
  111.                     Left            = Screen -> LeftEdge;
  112.                     Top             = Screen -> TopEdge ;
  113.                     Width           = Screen -> Width;
  114.                     Height          = Screen -> Height;
  115.                     PageWidth       = Width;
  116.                     PageHeight      = Height;
  117.                     Depth           = GetBitMapAttr(Screen -> RastPort . BitMap,BMA_DEPTH);
  118.                     }
  119.  
  120.                 if(BitMap = AllocBitMap(Width,Height,Depth,BMF_CLEAR,
  121.                         ((scr)?(Screen -> RastPort . BitMap):(Window -> RPort -> BitMap))))
  122.                 {
  123.                         ULONG   *ColourTable,
  124.                                          ModeID;
  125.                         LONG     NumColours;
  126.  
  127.                         NumColours = ((scr)?(Screen -> ViewPort . ColorMap -> Count):(Window -> WScreen -> ViewPort . ColorMap -> Count));
  128.  
  129.                         ModeID = GetVPModeID(((scr)?(&Screen -> ViewPort):(&Window -> WScreen -> ViewPort)));
  130.  
  131.                         RPort -> BitMap = BitMap;
  132.  
  133.                         ClipBlit(((scr)?(&Screen -> RastPort):(Window -> RPort)),0,0,RPort,0,0,Width,Height,0xC0);
  134.  
  135.                         WaitBlit();
  136.  
  137.                         if(ColourTable = (ULONG *)AllocVec(sizeof(ULONG) * 3 * NumColours,
  138.                                 MEMF_ANY))
  139.                         {
  140.                                 Object *Picture;
  141.  
  142.                                 GetRGB32(((scr)?(Screen -> ViewPort . ColorMap):(Window -> WScreen -> ViewPort . ColorMap)),0,NumColours,
  143.                                         ColourTable);
  144.  
  145.                                 UnlockIBase(IntuiLock);
  146.  
  147.                                 Locked = FALSE;
  148.  
  149.                                 if(Picture = NewDTObject("ActiveWindow",
  150.                                         DTA_SourceType, DTST_RAM,
  151.                                         DTA_GroupID,    GID_PICTURE,
  152.                                         PDTA_NumColors, NumColours,
  153.                                         PDTA_BitMap,    BitMap,
  154.                                         PDTA_ModeID,    ModeID,
  155.                                 TAG_DONE))
  156.                                 {
  157.                                         struct ColorRegister    *ColourMap;
  158.                                         struct BitMapHeader             *BitMapHeader;
  159.                                         ULONG                                   *Colours;
  160.  
  161.                                         if(GetDTAttrs(Picture,
  162.                                                 PDTA_BitMapHeader,      &BitMapHeader,
  163.                                                 PDTA_ColorRegisters,&ColourMap,
  164.                                                 PDTA_CRegs,                     &Colours,
  165.                                         TAG_DONE) == 3)
  166.                                         {
  167.                                                 BitMapHeader -> bmh_Left                = Left;
  168.                                                 BitMapHeader -> bmh_Top                 = Top;
  169.                                                 BitMapHeader -> bmh_Width               = Width;
  170.                                                 BitMapHeader -> bmh_Height              = Height;
  171.                                                 BitMapHeader -> bmh_Depth               = Depth;
  172.                                                 BitMapHeader -> bmh_PageWidth           = PageWidth;
  173.                                                 BitMapHeader -> bmh_PageHeight          = PageHeight;
  174.  
  175.                                                 CopyMem(ColourTable,Colours,
  176.                                                         3 * sizeof(ULONG) * NumColours);
  177.  
  178.                                                 while(NumColours--)
  179.                                                 {
  180.                                                         ColourMap -> red        = (UBYTE)((*Colours++) >> 24);
  181.                                                         ColourMap -> green      = (UBYTE)((*Colours++) >> 24);
  182.                                                         ColourMap -> blue       = (UBYTE)((*Colours++) >> 24);
  183.  
  184.                                                         ColourMap++;
  185.                                                 }
  186.  
  187.                                                 FreeVec(ColourTable);
  188.  
  189.                                                 FreeVec(RPort);
  190.  
  191.                                                 return(Picture);
  192.                                         }
  193.  
  194.                                         DisposeDTObject(Picture);
  195.  
  196.                                         BitMap = NULL;
  197.                                 }
  198.  
  199.                                 FreeVec(ColourTable);
  200.                         }
  201.  
  202.                         FreeBitMap(BitMap);
  203.                 }
  204.  
  205.                 if(Locked)
  206.                         UnlockIBase(IntuiLock);
  207.  
  208.                 FreeVec(RPort);
  209.         }
  210.  
  211.         return(NULL);
  212. }
  213. @
  214.  
  215.  
  216. 1.1
  217. log
  218. @Added Screen Grabing Support (GetPicture(BOOL screen))
  219. @
  220. text
  221. @d1 1
  222. a1 1
  223. /* $Id: wshot.c,v 1.1 1995/10/29 09:25:58 aris Exp $
  224. d83 1
  225. a83 1
  226.                     Depth           = GetBitMapAttr(Screen -> RPort -> BitMap,BMA_DEPTH);
  227. d87 1
  228. a87 1
  229.                         ((scr)?(Screen -> RPort -> BitMap):(Window -> RPort -> BitMap)))
  230. d99 1
  231. a99 1
  232.                         ClipBlit(((scr)?(Screen -> RPort):(Window -> RPort)),0,0,RPort,0,0,Width,Height,0xC0);
  233. @
  234.  
  235.  
  236. 1.0
  237. log
  238. @Initial revision
  239. @
  240. text
  241. @d1 1
  242. a1 1
  243. /* $Id$
  244. d41 1
  245. a41 1
  246. GetPicture(void)
  247. d51 3
  248. a53 3
  249.                                                  Width,Height,
  250.                                                  PageWidth,PageHeight,
  251.                                                  Depth;
  252. d55 1
  253. d61 1
  254. a61 1
  255.                 Window = IntuitionBase -> ActiveWindow;
  256. d63 1
  257. a63 7
  258.                 Left            = Window -> LeftEdge;
  259.                 Top                     = Window -> TopEdge;
  260.                 Width           = Window -> Width;
  261.                 Height          = Window -> Height;
  262.                 PageWidth       = Window -> WScreen -> Width;
  263.                 PageHeight      = Window -> WScreen -> Height;
  264.                 Depth           = GetBitMapAttr(Window -> RPort -> BitMap,BMA_DEPTH);
  265. d65 21
  266. d87 1
  267. a87 1
  268.                         Window -> RPort -> BitMap))
  269. d93 1
  270. a93 1
  271.                         NumColours = Window -> WScreen -> ViewPort . ColorMap -> Count;
  272. d95 1
  273. a95 1
  274.                         ModeID = GetVPModeID(&Window -> WScreen -> ViewPort);
  275. d99 1
  276. a99 1
  277.                         ClipBlit(Window -> RPort,0,0,RPort,0,0,Width,Height,0xC0);
  278. d108 1
  279. a108 1
  280.                                 GetRGB32(Window -> WScreen -> ViewPort . ColorMap,0,NumColours,
  281. d138 2
  282. a139 2
  283.                                                 BitMapHeader -> bmh_PageWidth   = PageWidth;
  284.                                                 BitMapHeader -> bmh_PageHeight  = PageHeight;
  285. @
  286.